package com.example.myapplication

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.EditText
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [shouye.newInstance] factory method to
 * create an instance of this fragment.
 */
class shouye : Fragment() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null

    private lateinit var recyclerView: RecyclerView
    private lateinit var adapter: DemoAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {



        val view = inflater.inflate(R.layout.fragment_shouye, container, false)




        recyclerView = view.findViewById(R.id.rv_demo)
        recyclerView.layoutManager = LinearLayoutManager(requireContext())

        // 初始化适配器并设置到RecyclerView
        adapter = DemoAdapter(createDemoDate())
        recyclerView.adapter = adapter
        // Inflate the layout for this fragment
        return view


    }

    private fun createDemoDate(): ArrayList<ItemBean> {

        val list = ArrayList<ItemBean>()

        val Item1 = ItemBean(R.drawable.a, "这些重大问题，习近平的回答掷地有声", "新华社新媒体")
        val Item2 =
            ItemBean(R.drawable.b, "习近平会见“元老会”代表团", "央视网新闻")

        val Item3 = ItemBean(R.drawable.c, "美媒：五角大楼盯上谷歌在华AI中心 谷歌忙安抚", "参考消息")
        val Item4 = ItemBean(R.drawable.d, "蔡英文财产曝光：存款5406万 名下拥6笔不动产", "人民日报海外网 120评论")
        for (i in 0 until 3) {
            list.add(Item1)
            list.add(Item2)
            list.add(Item3)
            list.add(Item4)
        }

        return list
    }

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment shouye.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            shouye().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}